/**
  * CMX application object
  * by Dave Kuhn
  * 
  */

// reference local blank image
Ext.BLANK_IMAGE_URL = 'lib/ext-2.0/resources/images/default/s.gif';

// create namespaces
Ext.namespace(
	'cmx', 
	'cmx.data',
	'cmx.dialog',
	'cmx.panel', 
	'cmx.tree', 
	'cmx.util', 
	'cmx.bo', 
	'cmx.menu'
);

cmx.App = function() {
	// private variables
	var viewport;
	var northPanel;
	var southPanel;
	var centerTabPanel;
	var eastPanel;	
	var northEastTabPanel;
	var southEastTabPanel;
	var siteTreePanel;
	var pagePropertyGrid;
	var westPanel;
	
	// private variables
	var initCookie = function() {
		Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	}	
	
	var initComponents = function() {
		
		northPanel = createNorthPanel();
		southPanel = createSouthPanel();
		eastPanel = createEastPanel();
		westPanel = createWestPanel();
		centerTabPanel = createCenterTabPanel();						
										
		viewport = new Ext.Viewport({
            layout:'border',
            items:[
				northPanel,
				southPanel,
				eastPanel,
				westPanel,
                centerTabPanel
        	]
        });
	}
	
	var createNorthPanel = function() {		
		
		var mainMenu = new cmx.menu.MainMenu({ 
	        region:'north'
	    });
		
		return mainMenu;
	}
	
	var createSouthPanel = function() {
		var panel = new Ext.Panel({
            region:'south',
            title:'Status',
            split:true,
            height: 100,
            minSize: 100,
            maxSize: 200,
            collapsible: true,
            margins:'0 0 0 0'
        });
		
		return panel;	
	}
	
	var createEastPanel = function() {
		northEastTabPanel = createNorthEastTabPanel();
		southEastTabPanel = createSouthEastTabPanel();
		
		var panel = new Ext.Panel({
	        region:'east',
			title:'&nbsp',
			layout:'border',
	        collapsible: true,
	        collapseMode: 'mini',
	        split:true,
	        width: 225,
	        minSize: 175,
	        maxSize: 400,
	        margins:'0 5 0 0',
	        items: [ 
				northEastTabPanel,
	            southEastTabPanel
			]
		});
		
		return panel;
	}
	
	var createCenterTabPanel = function() {
		var panel = new Ext.TabPanel({
            region:'center',
            deferredRender:false,
            activeTab:0,
			enableTabScroll:true,
            items:[{
                contentEl:'startPageContent',
                title: 'Start Page',
                closable:false,
                autoScroll:true,
                bodyStyle: 'padding: 10px'
            }]
        });
		
		return panel;
	}
	
	var createWestPanel = function() {
		var panel = new Ext.Panel({
            region:'west',
            contentEl:'west',
            title:'&nbsp',
            split:true,
            width: 200,
            minSize: 175,
            maxSize: 400,
            collapsible: true,
            collapseMode: 'mini',
            margins:'0 0 0 5',
            layout:'accordion',
            layoutConfig:{
                animate:true
            },
            items: [{
             	contentEl: 'west',
                title:'Tools',
                border:false,
                iconCls:'settings'
            },{
                title:'Templates',
                html:'<p>Some templates in here.</p>',
                border:false,
                iconCls:'nav'
            },{
                title:'Settings',
                html:'<p>Some settings in here.</p>',
                border:false,
                iconCls:'settings'
            }]
        });
		
		return panel;
	}
	
	var createSiteTreePanel = function() {
		return new cmx.tree.SiteTreePanel({
			el: "siteTreePanel",
			region:'north',
			closable: true,
			split:true,
	        autoScroll:true,	        
	        containerScroll: true
		});		
	}
	
	var createFileTreePanel = function() {
		
	}
	
	var createPagePropertyGrid = function() {
		var grid = new Ext.grid.PropertyGrid({
            title: 'Properties',
            closable: true,
            source: {
                "(name)": "Properties Grid",
                "grouping": false,
                "autoFitColumns": true,
                "productionQuality": false,
                "created": new Date(Date.parse('10/15/2006')),
                "tested": false,
                "version": .01,
                "borderWidth": 1
            }
        });
		
		return grid;	
	}
	
	var createNorthEastTabPanel = function() {
		siteTreePanel = createSiteTreePanel();
		fileTreePanel = createFileTreePanel();
		
		var panel = new Ext.TabPanel({
			region:'center',
			split:true,
            deferredRender:false,
            activeTab:0,
            tabPosition:'bottom',
			minSize: 175,
	        maxSize: 400,
            items: [
            	siteTreePanel
            ]
        });
		
		return panel;
	}
	
	var createSouthEastTabPanel = function() {
		pagePropertyGrid = createPagePropertyGrid();
		
		var panel = new Ext.TabPanel({
			region:'south',
			split:true,
            deferredRender:false,
            activeTab:0,
            tabPosition:'bottom',
            height: 185,
            items: [pagePropertyGrid]
        });
		
		return panel;
	}
	
	// public space
	return {
		// public properties
 
        // public methods
		init: function() {
			initCookie();
			initComponents();
		}
	}
}

        
       